﻿using HardcoreGame.Common.Helpers;
using HardcoreGame.Content.Projectiles.Sets.Heavy.Others;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.GameContent;
using Terraria.Graphics;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Projectiles.Sets.Heavy
{
    public class Reaper : HeavyMeleeProjectile
    {
        private int projectileCooldown = 0;
        public override float Interpolate(float x)
        {
            return (float)(x == 1f ? 1.0 : 1.0 - Math.Pow(2.0, (double)(-10f * x)));
        }
        public override float ModifyScale()
        {
            return 1f + interpPeakAmount * 0.2f;
        }
        public override void SetDefaults()
        {
            base.SetDefaults();
            drawAngleRangeMod = 1.4f;
            AttackRange = 3.226991f;
        }
        public override bool PreAI()
        {
            Player player = Main.player[Projectile.owner];
            if (projectileCooldown > 0)
            {
                projectileCooldown--;
            }
            if (projectileCooldown <= 0)
            {
                int projectileType = ModContent.ProjectileType<PumpkinScytheproj>();
                Vector2 mousePosition = Main.MouseWorld;
                Vector2 direction = mousePosition - player.Center;
                direction.Normalize();
                float speed = 0.25f;
                Vector2 velocity = direction * speed;
                Vector2 spawnPosition = player.Center + direction * 40f;
                Projectile.NewProjectile(Projectile.GetSource_FromAI(), spawnPosition, velocity, projectileType, player.HeldItem.damage, player.HeldItem.knockBack, player.whoAmI);
                projectileCooldown = 80;
            }
            return true;
        }
        public override void PostDraw(Color lightColor)
        {
            Texture2D tex = TextureAssets.Projectile[Projectile.type].Value;
            Main.spriteBatch.BeginBlendState(BlendState.NonPremultiplied, null, null, false, false, DrawMode.World, false);
            Main.spriteBatch.Draw(ModContent.Request<Texture2D>("HardcoreGame/Content/Projectiles/Sets/Heavy/Slash_Base").Value, staticPos + Projectile.velocity * (22f + 12f * swingProgress) * Projectile.scale - Main.screenPosition, null, new Color(169, 195, 41).MultiplyAlpha(interpPeakAmount * 0.15f), Projectile.velocity.ToRotation() + 1.5707964f, ModContent.Request<Texture2D>("HardcoreGame/Content/Projectiles/Sets/Heavy/Slash_Base").Value.Size() / 2f, new Vector2(2f, 1f + swingProgress), SpriteEffects.None, 0f);
            Main.spriteBatch.EndBlendState(false, DrawMode.World, true);
            Main.spriteBatch.Draw(tex, Projectile.Center - Main.screenPosition, null, lightColor, drawAngle, HandleOriginWithFlip(tex, new Vector2(7f, 53f)), drawScale, spriteFx, 0f);
        }       
    }
}
